<?php
	require('config.php');
	$shopId=$_REQUEST['shopId'];
	$sql="select deliveryCostTime,serviceStartTime,serviceEndTime from `".$oto."_shops` where `shopId`='{$shopId}'";
	$result=$db->query($sql);
	while($row=$result->fetch_assoc()){
		$shops_info[]=$row;//将取得的所有数据赋值给person_info数组
	}
	$time=time();
	$start=$shops_info[0]['serviceStartTime'];
	$end=$shops_info[0]['serviceEndTime'];
	$deliveryTime=$shops_info[0]['deliveryCostTime'];
	$z_start=explode('.',$start);
	$z_end=explode('.',$end);
	$a=date('Y-m-d '.$z_start[0].':'.$z_start[1].'0:00',$time);
	$b=date('Y-m-d '.$z_end[0].':'.$z_end[1].'0:00',$time);
	$c=date('Y-m-d '.$z_end[0].':00:00',$time);
	$start_time=strtotime($a);
	$end_time=strtotime($b);
	$wm=strtotime($c)+3600;
	// $a=date('Y-m-d H:i:s',$start_time);
	// $b=date('Y-m-d H:i:s',$end_time);
	$t=0;
	if($end_time==$wm-1200) $wm=$wm-1200;
	else if($end_time>$wm-1200)
	{
		$data[0]['time_list'][$t]=date('H:i',$end_time);
		$t++;
		$wm=$wm-1200;
	}
	else if($end_time==$wm-2400) $wm=$wm-2400;
	else if($end_time>$wm-2400) 
	{
		$data[0]['time_list'][$t]=date('H:i',$end_time);
		$t++;
		$wm=$wm-2400;
	}
	else if($end_time==$wm-3600) $wm=$wm-3600;
	else if($end_time>$wm-3600) 
	{
		$data[0]['time_list'][$t]=date('H:i',$end_time);
		$t++;
		$wm=$wm-3600;
	}
	for($i=$wm;$i>=$start_time && $i>($time+$deliveryTime*60);$i-=1200)
	{
		$data[0]['time_list'][$t]=date('H:i',$i);
		$t++;
	}
	$data[0]['time_list'][$t]=date('H:i',($time+$deliveryTime*60));
	$t++;
	for($i=0;$i<$t;$i++)
	{
		for($j=$i;$j<$t;$j++)
		{
			if($data[0]['time_list'][$i]>$data[0]['time_list'][$j])
			{
				$tt=$data[0]['time_list'][$i];
				$data[0]['time_list'][$i]=$data[0]['time_list'][$j];
				$data[0]['time_list'][$j]=$tt;
			}
		}
	}
	$data[0]['time_list'][0]="尽快送达(预计".$data[0]['time_list'][0].")";
	for($i=1;$i<$t-1;$i++)
	{
		$data[0]['time_list'][$i]=$data[0]['time_list'][$i]."-".$data[0]['time_list'][$i+1];
	}
	array_splice($data[0]['time_list'], $t-1, 1);
	if($t==0) $data[0]['time_list']=[];
	$data[0]['serviceStartTime_for_num']=$start_time;
	$data[0]['serviceEndTime_for_num']=$end_time;
	$data[0]['serviceStartTime_for_str']=date('Y-m-d H:i:s',$start_time);
	$data[0]['serviceEndTime_for_str']=date('Y-m-d H:i:s',$end_time);
	$data[0]['time_for_num']=$time;
	$data[0]['time_for_str']=date('Y-m-d H:i:s',$time);
	echo json_encode($data);
?>